  <template>
  <div>
    <div style="margin-bottom: 20px;">编辑项目</div>
    <el-form ref="form" :model="sizeForm" label-width="80px" size="mini">
      <el-form-item label="项目编号">
        <el-input v-model="sizeForm.projectId"></el-input>
      </el-form-item>
      <el-form-item label="项目名称">
        <el-input v-model="sizeForm.projectName"></el-input>
      </el-form-item>
      <el-form-item label="项目模板">
        <el-select v-model="sizeForm.projectTemplate" placeholder="请选择项目模板">
          <el-option label="工程管理" value="工程管理"></el-option>
          <el-option label="项目研发" value="项目研发"></el-option>
          <el-option label="招牌新闻" value="招牌新闻"></el-option>
          <el-option label="投标" value="投标"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目周期">
        <el-row :gutter="20">
          <el-col :span="11">
            <el-date-picker type="date" placeholder="选择日期" v-model="sizeForm.projectCycle"
              style="width: 100%;"></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="项目负责人">
        <el-input v-model="sizeForm.projectLeader"></el-input>
      </el-form-item>
      <el-form-item label="紧急程度">
        <el-select v-model="sizeForm.emergencyDegree" placeholder="请选择">
          <el-option label="高" value="高"></el-option>
          <el-option label="很高" value="很高"></el-option>
          <el-option label="非常高" value="非常高"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="优先级别">
        <el-select v-model="sizeForm.priorityLevel" placeholder="请选择">
          <el-option label="高" value="高"></el-option>
          <el-option label="低" value="低"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目审批人">
        <el-input v-model="sizeForm.projectApprover"></el-input>
      </el-form-item>
      <el-form-item label="项目监控人">
        <el-input v-model="sizeForm.projectSupervisor"></el-input>
      </el-form-item>
      <el-form-item label="项目团队">
        <el-input v-model="sizeForm.projectTeam"></el-input>
      </el-form-item>
      <el-form-item label="项目描述">
        <tinymce :width="595" :height="300" v-model="sizeForm.projectDescription" :key="tinymceFlag"></tinymce>
      </el-form-item>
      <el-form-item label="创建人">
        <el-input v-model="sizeForm.creator"></el-input>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="sizeForm.creationTime" type="datetime" placeholder="选择日期时间" default-time="12:00:00">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确认</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Tinymce from "@/components/Tinymce";
import { addProject, updateProject } from '../../api/project'
import moment from 'moment';
import { localeData } from "moment/moment";

export default {
  components: { Tinymce },
  data() {
    return {
      sizeForm: {
        projectId: '',
        projectId: '',
        projectName: '',
        projectTemplate: '',
        projectStartDate: '',
        projectCycle: '',
        projectLeader: '',
        emergencyDegree: '',
        priorityLevel: '',
        projectApprover: '',
        projectSupervisor: '',
        projectTeam: '',
        projectDescription: '',
        creator: '',
        creationTime: '',
      },
      loading: false,
      editFormVisible: false,
      isEdit: false,
      tinymceFlag: 1,
    };
  },
  beforeDestroy() {
    this.tinymce && this.tinymce.destroy();
  },
  methods: {
    onSubmit(){
      this.$router.push('/xiangmu/xianmu')
    },
    onCancel() {
      this.$router.push('/xiangmu/xianmu')
    },



    onSubmit() {
      let data = {
        projectId: this.sizeForm.projectId,
        projectName: this.sizeForm.projectName,
        projectTemplate: this.sizeForm.projectTemplate,
        projectCycle: moment(this.sizeForm.projectCycle).format('YYYY-MM-DD'),
        projectLeader: this.sizeForm.projectLeader,
        emergencyDegree: this.sizeForm.emergencyDegree,
        priorityLevel: this.sizeForm.priorityLevel,
        projectApprover: this.sizeForm.projectApprover,
        projectSupervisor: this.sizeForm.projectSupervisor,
        projectTeam: this.sizeForm.projectTeam,
        projectDescription: this.sizeForm.projectDescription,
        creator: this.sizeForm.creator,
        creationTime: moment(this.sizeForm.creationTime).format('YYYY-MM-DD'),
      };
      console.log(data);

      updateProject(data).then(res => {
        console.log(res);
        if (res.code === 200) {
          this.$message.success('修改成功');
          this.$router.push('/xiangmu/xianmu');
          this.editFormVisible = false;
        } else {
          this.$message.error('修改失败');
        }
      })
  },
  localeData() {
    let getdata = JSON.parse(localStorage.getItem('projectData'));
    console.log(getdata);
    this.sizeForm.projectId = getdata.projectId;
    this.sizeForm.projectName = getdata.projectName;
    this.sizeForm.projectTemplate = getdata.projectTemplate;
    this.sizeForm.projectCycle = moment(getdata.projectCycle).format('YYYY-MM-DD');
    this.sizeForm.projectLeader = getdata.projectLeader;
    this.sizeForm.emergencyDegree = getdata.emergencyDegree;
    this.sizeForm.priorityLevel = getdata.priorityLevel;
    this.sizeForm.projectApprover = getdata.projectApprover;
    this.sizeForm.projectSupervisor = getdata.projectSupervisor;
    this.sizeForm.projectTeam = getdata.projectTeam;
    this.sizeForm.projectDescription = getdata.projectDescription;
    this.sizeForm.creator = getdata.creator;
    this.sizeForm.creationTime = moment(getdata.creationTime).format('YYYY-MM-DD HH:mm:ss');
    
  }
},
mounted(){
  this.localeData();
}
}
</script>

<style>
.el-select .el-input {
  width: 130px;
}

.input-with-select .el-input-group__prepend {
  background-color: #fff;
}
</style>